Como usar quarto

Author

Nixon Pizarro

1 Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

1.1 Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed). # como usar cuarto?

1.2 fuentes

  • Negrita: esta es una fuente negrita
  • Cursia: Solamun Tuberosum

1.3 Formulas matemàticas

Este es el area de una circunferencia \(Area_{circunferencia}=pi\cdot r^2\)

Esta es una formula cualquiera \[\frac{\left(2x-1\right)^2-1}{4}=k\]

#Mi primera pagina web. 1. Tener mi proyecto 1. conectar mi poryecto a github 1. Tener un archivo en formato html llamado index.hetml 1. Activar Gi thub pages

2 Modelos lineales mixtos

2.1 Importar datos

source('https://inkaverse.com/setup.r')
ℹ The googlesheets4 package is using a cached token for
  'pizarrozavaletayonel949@gmail.com'.
ℹ The googledrive package is using a cached token for
  'pizarrozavaletayonel949@gmail.com'.
url <- "https://docs.google.com/spreadsheets/d/15r7ZwcZZHbEgltlF6gSFvCTFA-CFzVBWwg3mFlRyKPs/edit?gid=172957346#gid=172957346"

gs <- url %>% 
  as_sheets_id()

fb <- gs %>% 
  range_read("fb")


str(fb)
## tibble [150 × 18] (S3: tbl_df/tbl/data.frame)
##  $ riego  : chr [1:150] "sequia" "sequia" "irrigado" "sequia" ...
##  $ geno   : chr [1:150] "G01" "G02" "G01" "G02" ...
##  $ block  : num [1:150] 2 4 3 1 2 5 1 4 2 1 ...
##  $ bloque : chr [1:150] "II" "IV" "III" "I" ...
##  $ spad_29: num [1:150] 56.3 52.7 49.2 55.5 58.2 43.5 57.4 56.1 61 60.3 ...
##  $ spad_83: num [1:150] 41.1 47.9 41.6 44.2 32.6 37.8 42.5 35.9 57.5 41.8 ...
##  $ rwc_84 : num [1:150] 61.5 63.2 67.7 64.9 74.5 ...
##  $ op_84  : num [1:150] -2.43 -3.03 -2.5 -2.4 -2.27 ...
##  $ leafdw : num [1:150] 13.28 9.42 18.22 8.84 14.55 ...
##  $ stemdw : num [1:150] 14.87 8.63 24.19 6.58 12.63 ...
##  $ rootdw : num [1:150] 3.83 2.1 3.16 2 1.83 2.83 2.28 3.65 4.04 4.17 ...
##  $ tubdw  : num [1:150] 19.8 17.7 38 13.5 51.1 ...
##  $ biomdw : num [1:150] 51.8 37.8 83.6 30.9 80.2 ...
##  $ hi     : num [1:150] 0.45 0.43 0.455 0.437 0.638 ...
##  $ ttrans : num [1:150] 4.5 3.54 8.39 2.9 7.37 ...
##  $ wue    : num [1:150] 11.51 10.69 9.97 10.65 10.88 ...
##  $ twue   : num [1:150] 4.4 4.99 4.53 4.65 6.94 ...
##  $ lfa    : num [1:150] 2900 2619 7579 2450 5413 ...

2.2 Modelo lineal lfa

modelo <- aov(formula = lfa ~  bloque + riego + geno + riego*geno
          , data = fb)

anova(modelo)
## Analysis of Variance Table
## 
## Response: lfa
##             Df    Sum Sq   Mean Sq   F value              Pr(>F)    
## bloque       4   3435339    858835    1.5616              0.1892    
## riego        1 788556926 788556926 1433.7957 <0.0000000000000002 ***
## geno        14 261729564  18694969   33.9922 <0.0000000000000002 ***
## riego:geno  14 108147972   7724855   14.0457 <0.0000000000000002 ***
## Residuals  116  63797516    549979                                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

plot(modelo)

2.2.1 boxplot

ggplot(fb, aes(x = geno, y = lfa, colour = riego)) +
  geom_boxplot(outlier.colour = "red", outlier.shape = 16, outlier.size = 2) +
  labs(title = "Boxplot con interacción de niveles de riego y genotipo",
       x = "Interacción Riego y Genotipo",
       y = "Area Folicar (cm^2)")

  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))  # Inclinar etiquetas del eje X
## List of 136
##  $ line                            :List of 6
##   ..$ colour       : chr "black"
##   ..$ linewidth    : num 0.5
##   ..$ linetype     : num 1
##   ..$ lineend      : chr "butt"
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ rect                            :List of 5
##   ..$ fill         : chr "white"
##   ..$ colour       : chr "black"
##   ..$ linewidth    : num 0.5
##   ..$ linetype     : num 1
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ text                            :List of 11
##   ..$ family       : chr ""
##   ..$ face         : chr "plain"
##   ..$ colour       : chr "black"
##   ..$ size         : num 11
##   ..$ hjust        : num 0.5
##   ..$ vjust        : num 0.5
##   ..$ angle        : num 0
##   ..$ lineheight   : num 0.9
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ title                           : NULL
##  $ aspect.ratio                    : NULL
##  $ axis.title                      : NULL
##  $ axis.title.x                    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 2.75points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.top                :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 2.75points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.bottom             : NULL
##  $ axis.title.y                    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : num 90
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.75points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y.left               : NULL
##  $ axis.title.y.right              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : num -90
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.75points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text                       :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : chr "grey30"
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 1
##   ..$ vjust        : num 1
##   ..$ angle        : num 45
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 2.2points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.top                 :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 2.2points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.bottom              : NULL
##  $ axis.text.y                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 1
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.2points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y.left                : NULL
##  $ axis.text.y.right               :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.2points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.theta                 : NULL
##  $ axis.text.r                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0.5
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.2points 0points 2.2points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.ticks                      : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.ticks.x                    : NULL
##  $ axis.ticks.x.top                : NULL
##  $ axis.ticks.x.bottom             : NULL
##  $ axis.ticks.y                    : NULL
##  $ axis.ticks.y.left               : NULL
##  $ axis.ticks.y.right              : NULL
##  $ axis.ticks.theta                : NULL
##  $ axis.ticks.r                    : NULL
##  $ axis.minor.ticks.x.top          : NULL
##  $ axis.minor.ticks.x.bottom       : NULL
##  $ axis.minor.ticks.y.left         : NULL
##  $ axis.minor.ticks.y.right        : NULL
##  $ axis.minor.ticks.theta          : NULL
##  $ axis.minor.ticks.r              : NULL
##  $ axis.ticks.length               : 'simpleUnit' num 2.75points
##   ..- attr(*, "unit")= int 8
##  $ axis.ticks.length.x             : NULL
##  $ axis.ticks.length.x.top         : NULL
##  $ axis.ticks.length.x.bottom      : NULL
##  $ axis.ticks.length.y             : NULL
##  $ axis.ticks.length.y.left        : NULL
##  $ axis.ticks.length.y.right       : NULL
##  $ axis.ticks.length.theta         : NULL
##  $ axis.ticks.length.r             : NULL
##  $ axis.minor.ticks.length         : 'rel' num 0.75
##  $ axis.minor.ticks.length.x       : NULL
##  $ axis.minor.ticks.length.x.top   : NULL
##  $ axis.minor.ticks.length.x.bottom: NULL
##  $ axis.minor.ticks.length.y       : NULL
##  $ axis.minor.ticks.length.y.left  : NULL
##  $ axis.minor.ticks.length.y.right : NULL
##  $ axis.minor.ticks.length.theta   : NULL
##  $ axis.minor.ticks.length.r       : NULL
##  $ axis.line                       : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.line.x                     : NULL
##  $ axis.line.x.top                 : NULL
##  $ axis.line.x.bottom              : NULL
##  $ axis.line.y                     : NULL
##  $ axis.line.y.left                : NULL
##  $ axis.line.y.right               : NULL
##  $ axis.line.theta                 : NULL
##  $ axis.line.r                     : NULL
##  $ legend.background               : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.margin                   : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
##   ..- attr(*, "unit")= int 8
##  $ legend.spacing                  : 'simpleUnit' num 11points
##   ..- attr(*, "unit")= int 8
##  $ legend.spacing.x                : NULL
##  $ legend.spacing.y                : NULL
##  $ legend.key                      : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.key.size                 : 'simpleUnit' num 1.2lines
##   ..- attr(*, "unit")= int 3
##  $ legend.key.height               : NULL
##  $ legend.key.width                : NULL
##  $ legend.key.spacing              : 'simpleUnit' num 5.5points
##   ..- attr(*, "unit")= int 8
##  $ legend.key.spacing.x            : NULL
##  $ legend.key.spacing.y            : NULL
##  $ legend.frame                    : NULL
##  $ legend.ticks                    : NULL
##  $ legend.ticks.length             : 'rel' num 0.2
##  $ legend.axis.line                : NULL
##  $ legend.text                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.text.position            : NULL
##  $ legend.title                    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.title.position           : NULL
##  $ legend.position                 : chr "right"
##  $ legend.position.inside          : NULL
##  $ legend.direction                : NULL
##  $ legend.byrow                    : NULL
##  $ legend.justification            : chr "center"
##  $ legend.justification.top        : NULL
##  $ legend.justification.bottom     : NULL
##  $ legend.justification.left       : NULL
##  $ legend.justification.right      : NULL
##  $ legend.justification.inside     : NULL
##  $ legend.location                 : NULL
##  $ legend.box                      : NULL
##  $ legend.box.just                 : NULL
##  $ legend.box.margin               : 'margin' num [1:4] 0cm 0cm 0cm 0cm
##   ..- attr(*, "unit")= int 1
##  $ legend.box.background           : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.box.spacing              : 'simpleUnit' num 11points
##   ..- attr(*, "unit")= int 8
##   [list output truncated]
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi TRUE
##  - attr(*, "validate")= logi TRUE

2.3 Modelo lineal de hi

modelo <- aov(formula = hi ~  bloque + riego + geno + riego*geno
          , data = fb)

anova(modelo)
## Analysis of Variance Table
## 
## Response: hi
##             Df  Sum Sq  Mean Sq F value                Pr(>F)    
## bloque       4 0.09111 0.022778  7.0747         0.00003925028 ***
## riego        1 0.12176 0.121758 37.8165         0.00000001135 ***
## geno        14 2.70077 0.192912 59.9161 < 0.00000000000000022 ***
## riego:geno  14 0.07762 0.005544  1.7219               0.06019 .  
## Residuals  116 0.37349 0.003220                                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

plot(modelo)

2.3.1 boxplot

ggplot(fb, aes(x = geno, y = hi, colour = riego)) +
  geom_boxplot(outlier.colour = "red", outlier.shape = 16, outlier.size = 2) +
  labs(title = "Boxplot con interacción de niveles de riego y genotipo",
       x = "Interacción Riego y Genotipo",
       y = "Indice de Cosecha  (cm^2)")

  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))  # Inclinar etiquetas del eje X
## List of 136
##  $ line                            :List of 6
##   ..$ colour       : chr "black"
##   ..$ linewidth    : num 0.5
##   ..$ linetype     : num 1
##   ..$ lineend      : chr "butt"
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ rect                            :List of 5
##   ..$ fill         : chr "white"
##   ..$ colour       : chr "black"
##   ..$ linewidth    : num 0.5
##   ..$ linetype     : num 1
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ text                            :List of 11
##   ..$ family       : chr ""
##   ..$ face         : chr "plain"
##   ..$ colour       : chr "black"
##   ..$ size         : num 11
##   ..$ hjust        : num 0.5
##   ..$ vjust        : num 0.5
##   ..$ angle        : num 0
##   ..$ lineheight   : num 0.9
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ title                           : NULL
##  $ aspect.ratio                    : NULL
##  $ axis.title                      : NULL
##  $ axis.title.x                    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 2.75points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.top                :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 2.75points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.bottom             : NULL
##  $ axis.title.y                    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : num 90
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.75points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y.left               : NULL
##  $ axis.title.y.right              :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : num -90
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.75points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text                       :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : chr "grey30"
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 1
##   ..$ vjust        : num 1
##   ..$ angle        : num 45
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 2.2points 0points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.top                 :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 2.2points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.bottom              : NULL
##  $ axis.text.y                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 1
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.2points 0points 0points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y.left                : NULL
##  $ axis.text.y.right               :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.2points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.theta                 : NULL
##  $ axis.text.r                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0.5
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : 'margin' num [1:4] 0points 2.2points 0points 2.2points
##   .. ..- attr(*, "unit")= int 8
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.ticks                      : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.ticks.x                    : NULL
##  $ axis.ticks.x.top                : NULL
##  $ axis.ticks.x.bottom             : NULL
##  $ axis.ticks.y                    : NULL
##  $ axis.ticks.y.left               : NULL
##  $ axis.ticks.y.right              : NULL
##  $ axis.ticks.theta                : NULL
##  $ axis.ticks.r                    : NULL
##  $ axis.minor.ticks.x.top          : NULL
##  $ axis.minor.ticks.x.bottom       : NULL
##  $ axis.minor.ticks.y.left         : NULL
##  $ axis.minor.ticks.y.right        : NULL
##  $ axis.minor.ticks.theta          : NULL
##  $ axis.minor.ticks.r              : NULL
##  $ axis.ticks.length               : 'simpleUnit' num 2.75points
##   ..- attr(*, "unit")= int 8
##  $ axis.ticks.length.x             : NULL
##  $ axis.ticks.length.x.top         : NULL
##  $ axis.ticks.length.x.bottom      : NULL
##  $ axis.ticks.length.y             : NULL
##  $ axis.ticks.length.y.left        : NULL
##  $ axis.ticks.length.y.right       : NULL
##  $ axis.ticks.length.theta         : NULL
##  $ axis.ticks.length.r             : NULL
##  $ axis.minor.ticks.length         : 'rel' num 0.75
##  $ axis.minor.ticks.length.x       : NULL
##  $ axis.minor.ticks.length.x.top   : NULL
##  $ axis.minor.ticks.length.x.bottom: NULL
##  $ axis.minor.ticks.length.y       : NULL
##  $ axis.minor.ticks.length.y.left  : NULL
##  $ axis.minor.ticks.length.y.right : NULL
##  $ axis.minor.ticks.length.theta   : NULL
##  $ axis.minor.ticks.length.r       : NULL
##  $ axis.line                       : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.line.x                     : NULL
##  $ axis.line.x.top                 : NULL
##  $ axis.line.x.bottom              : NULL
##  $ axis.line.y                     : NULL
##  $ axis.line.y.left                : NULL
##  $ axis.line.y.right               : NULL
##  $ axis.line.theta                 : NULL
##  $ axis.line.r                     : NULL
##  $ legend.background               : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.margin                   : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
##   ..- attr(*, "unit")= int 8
##  $ legend.spacing                  : 'simpleUnit' num 11points
##   ..- attr(*, "unit")= int 8
##  $ legend.spacing.x                : NULL
##  $ legend.spacing.y                : NULL
##  $ legend.key                      : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.key.size                 : 'simpleUnit' num 1.2lines
##   ..- attr(*, "unit")= int 3
##  $ legend.key.height               : NULL
##  $ legend.key.width                : NULL
##  $ legend.key.spacing              : 'simpleUnit' num 5.5points
##   ..- attr(*, "unit")= int 8
##  $ legend.key.spacing.x            : NULL
##  $ legend.key.spacing.y            : NULL
##  $ legend.frame                    : NULL
##  $ legend.ticks                    : NULL
##  $ legend.ticks.length             : 'rel' num 0.2
##  $ legend.axis.line                : NULL
##  $ legend.text                     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : 'rel' num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.text.position            : NULL
##  $ legend.title                    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.title.position           : NULL
##  $ legend.position                 : chr "right"
##  $ legend.position.inside          : NULL
##  $ legend.direction                : NULL
##  $ legend.byrow                    : NULL
##  $ legend.justification            : chr "center"
##  $ legend.justification.top        : NULL
##  $ legend.justification.bottom     : NULL
##  $ legend.justification.left       : NULL
##  $ legend.justification.right      : NULL
##  $ legend.justification.inside     : NULL
##  $ legend.location                 : NULL
##  $ legend.box                      : NULL
##  $ legend.box.just                 : NULL
##  $ legend.box.margin               : 'margin' num [1:4] 0cm 0cm 0cm 0cm
##   ..- attr(*, "unit")= int 1
##  $ legend.box.background           : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.box.spacing              : 'simpleUnit' num 11points
##   ..- attr(*, "unit")= int 8
##   [list output truncated]
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi TRUE
##  - attr(*, "validate")= logi TRUE

2.4 Modelo lineal mixto: lfa

library(lme4)

library(lmerTest)

model <- lme4::lmer(formula = lfa ~ riego * geno + (1|bloque), data = fb)
anova(model)
## Analysis of Variance Table
##            npar    Sum Sq   Mean Sq  F value
## riego         1 788556926 788556926 1433.796
## geno         14 261729564  18694969   33.992
## riego:geno   14 108147972   7724855   14.046

plot(modelo)


ol <- boxplot(lfa ~ riego * geno, fb)

ol
## $stats
##         [,1]    [,2]    [,3]    [,4]    [,5]    [,6]     [,7]    [,8]     [,9]
## [1,] 6539.86 2900.00 4631.00 2449.59 5305.77 1811.97  8569.08 2511.13  7205.94
## [2,] 7038.08 2994.58 5162.74 2487.28 5369.88 1953.50  8867.03 2889.83  8189.67
## [3,] 7578.79 2999.66 5233.55 2618.85 5412.51 2107.76  9791.10 3010.27  8913.12
## [4,] 7750.00 3100.00 6478.14 2966.18 5450.00 2147.55 10305.61 3218.63  9793.99
## [5,] 7982.73 3203.70 7392.38 3063.35 5545.69 2274.48 10811.84 3263.70 10291.06
##        [,10]   [,11]   [,12]   [,13]   [,14]   [,15]   [,16]    [,17]   [,18]
## [1,] 1657.64 6576.65 3159.54 1065.26  216.31 6998.00 2021.37  8533.54 2781.32
## [2,] 1700.00 6857.13 3198.96 1068.97  495.83 7012.74 2278.60  8924.78 2961.78
## [3,] 1771.80 6938.90 3381.68 1140.05  782.10 7310.01 2319.71 10764.71 3150.00
## [4,] 1821.46 7864.08 3450.00 1607.25  811.45 7469.58 2550.51 10919.31 3235.10
## [5,] 1967.49 9040.06 3550.19 1989.25 1097.98 7643.80 2697.93 12296.22 3238.41
##        [,19]   [,20]   [,21]   [,22]   [,23]   [,24]   [,25]   [,26]   [,27]
## [1,] 4249.18 2909.10 3966.33 1556.38 6111.43 2400.00 7180.79 3062.34 6049.52
## [2,] 4743.16 2909.10 6210.41 1942.23 7164.03 2425.26 8256.98 3110.00 7895.00
## [3,] 5171.21 2940.95 7225.02 2237.88 7194.26 2438.98 8750.00 3120.00 8978.89
## [4,] 6028.93 3096.00 8005.55 2274.26 8012.79 2480.00 9430.43 3146.19 9221.24
## [5,] 6164.24 3136.07 8867.09 2301.31 8603.78 2487.78 9743.70 3191.97 9776.01
##        [,28]   [,29]   [,30]
## [1,] 3318.36 6270.00 1560.00
## [2,] 3326.93 6302.79 1560.00
## [3,] 3449.76 6304.88 1601.06
## [4,] 3664.65 6435.00 1750.00
## [5,] 3811.99 6522.46 1814.84
## 
## $n
##  [1] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
## 
## $conf
##          [,1]    [,2]     [,3]    [,4]     [,5]     [,6]      [,7]     [,8]
## [1,] 7075.749 2925.17 4304.092 2280.46 5355.897 1970.645  8774.603 2777.941
## [2,] 8081.831 3074.15 6163.008 2957.24 5469.123 2244.875 10807.597 3242.599
##           [,9]    [,10]    [,11]    [,12]     [,13]     [,14]    [,15]    [,16]
## [1,]  7779.512 1685.977 6227.392 3204.296  759.7027  559.0837 6987.208 2127.579
## [2,] 10046.728 1857.623 7650.408 3559.064 1520.3973 1005.1163 7632.812 2511.841
##         [,17]    [,18]    [,19]    [,20]    [,21]    [,22]    [,23]    [,24]
## [1,]  9355.38 2956.873 4262.688 2808.887 5956.579 2003.268 6594.528 2400.301
## [2,] 12174.04 3343.127 6079.732 3073.013 8493.461 2472.492 7793.992 2477.659
##         [,25]    [,26]    [,27]    [,28]    [,29]    [,30]
## [1,] 7920.843 3094.428 8041.772 3211.128 6211.461 1466.806
## [2,] 9579.157 3145.572 9916.008 3688.392 6398.299 1735.314
## 
## $out
## [1] 2541.12 1176.63
## 
## $group
## [1] 20 30
## 
## $names
##  [1] "irrigado.G01" "sequia.G01"   "irrigado.G02" "sequia.G02"   "irrigado.G03"
##  [6] "sequia.G03"   "irrigado.G04" "sequia.G04"   "irrigado.G05" "sequia.G05"  
## [11] "irrigado.G06" "sequia.G06"   "irrigado.G07" "sequia.G07"   "irrigado.G08"
## [16] "sequia.G08"   "irrigado.G09" "sequia.G09"   "irrigado.G10" "sequia.G10"  
## [21] "irrigado.G11" "sequia.G11"   "irrigado.G12" "sequia.G12"   "irrigado.G13"
## [26] "sequia.G13"   "irrigado.G14" "sequia.G14"   "irrigado.G15" "sequia.G15"

2.4.1 Eliminar valores atipicos

library(inti)

model <- remove_outliers(data = fb
                             , formula = lfa ~ riego * geno + (1|bloque)
                         , plot_diag = T)
model
## $data
## $data$raw
## # A tibble: 150 × 5
##    index riego    geno  bloque   lfa
##    <chr> <chr>    <chr> <chr>  <dbl>
##  1 1     sequia   G01   II     2900 
##  2 2     sequia   G02   IV     2619.
##  3 3     irrigado G01   III    7579.
##  4 4     sequia   G02   I      2450.
##  5 5     irrigado G03   II     5413.
##  6 6     irrigado G04   V      9791.
##  7 7     irrigado G01   I      7038.
##  8 8     irrigado G05   IV     9794.
##  9 9     sequia   G06   II     3199.
## 10 10    sequia   G05   I      1658.
## # ℹ 140 more rows
## 
## $data$clean
##     index    riego geno bloque      lfa
## 1       1   sequia  G01     II  2900.00
## 2       2   sequia  G02     IV  2618.85
## 3       3 irrigado  G01    III  7578.79
## 4       4   sequia  G02      I  2449.59
## 5       5 irrigado  G03     II  5412.51
## 6       6 irrigado  G04      V  9791.10
## 7       7 irrigado  G01      I  7038.08
## 8       8 irrigado  G05     IV  9793.99
## 9       9   sequia  G06     II  3198.96
## 10     10   sequia  G05      I  1657.64
## 11     11 irrigado  G01     II  7982.73
## 12     12   sequia  G07     II  1097.98
## 13     13 irrigado  G08     II  7310.01
## 14     14 irrigado  G06    III  6576.65
## 15     15 irrigado  G09    III 10764.71
## 16     16 irrigado  G10     II  5171.21
## 17     17   sequia  G11      I  1556.38
## 18     18   sequia  G12    III  2425.26
## 19     19 irrigado  G07      I  1065.26
## 20     20 irrigado  G04     II 10811.84
## 21     21 irrigado  G13     II  9743.70
## 22     22 irrigado  G14    III  7895.00
## 23     23 irrigado  G04     IV 10305.61
## 24     24   sequia  G04      V  3218.63
## 25     25   sequia  G08      V  2697.93
## 26     26   sequia  G04    III  3263.70
## 27     27   sequia  G01     IV  2994.58
## 28     28 irrigado  G10      I  6164.24
## 29     29 irrigado  G08      V  7469.58
## 30     30 irrigado  G02      V  5233.55
## 31     31 irrigado  G07    III  1607.25
## 32     32 irrigado  G08      I  6998.00
## 33     33 irrigado  G14      V  8978.89
## 34     34 irrigado  G03      I  5545.69
## 35     35   sequia  G13    III  3120.00
## 36     36   sequia  G01      V  2999.66
## 37     37   sequia  G03      I  2274.48
## 38     38 irrigado  G15    III  6302.79
## 39     39 irrigado  G03     IV  5305.77
## 40     40 irrigado  G09     IV       NA
## 41     41 irrigado  G11     II       NA
## 42     42   sequia  G03      V  2147.55
## 43     43   sequia  G11    III  2301.31
## 44     44 irrigado  G06      V       NA
## 45     45   sequia  G05      V  1771.80
## 46     46   sequia  G08     IV  2021.37
## 47     47 irrigado  G11     IV  8005.55
## 48     48   sequia  G11     II  1942.23
## 49     49 irrigado  G10    III  6028.93
## 50     50   sequia  G06     IV  3550.19
## 51     51   sequia  G09      I  3238.41
## 52     52 irrigado  G11      I  6210.41
## 53     53   sequia  G11     IV  2237.88
## 54     54 irrigado  G15     IV  6270.00
## 55     55 irrigado  G13     IV  9430.43
## 56     56   sequia  G14      V  3664.65
## 57     57 irrigado  G02     IV       NA
## 58     58 irrigado  G09     II       NA
## 59     59 irrigado  G02    III  5162.74
## 60     60   sequia  G08    III  2550.51
## 61     61 irrigado  G06     II  6938.90
## 62     62   sequia  G13     IV  3062.34
## 63     63   sequia  G14    III  3449.76
## 64     64   sequia  G04     II  2511.13
## 65     65 irrigado  G11    III       NA
## 66     66 irrigado  G07     II  1068.97
## 67     67 irrigado  G08     IV  7643.80
## 68     68   sequia  G05     IV  1821.46
## 69     69 irrigado  G04      I  8569.08
## 70     70 irrigado  G11      V  7225.02
## 71     71 irrigado  G12      I  7194.26
## 72     72   sequia  G14     IV  3318.36
## 73     73   sequia  G07    III   811.45
## 74     74 irrigado  G03    III  5450.00
## 75     75   sequia  G01      I  3100.00
## 76     76   sequia  G04      I  3010.27
## 77     77   sequia  G03     II  2107.76
## 78     78 irrigado  G15     II  6304.88
## 79     79   sequia  G12     IV  2480.00
## 80     80   sequia  G12      I  2400.00
## 81     81   sequia  G08      I  2319.71
## 82     82   sequia  G05     II  1700.00
## 83     83   sequia  G02     II  2966.18
## 84     84   sequia  G10      I  3136.07
## 85     85   sequia  G15      I  1814.84
## 86     86 irrigado  G07      V  1140.05
## 87     87   sequia  G10      V  2909.10
## 88     88   sequia  G13     II  3110.00
## 89     89   sequia  G07      V   495.83
## 90     90   sequia  G03    III  1953.50
## 91     91   sequia  G15     IV  1750.00
## 92     92   sequia  G13      I  3191.97
## 93     93   sequia  G03     IV  1811.97
## 94     94 irrigado  G10      V  4249.18
## 95     95   sequia  G13      V  3146.19
## 96     96   sequia  G09     II  3235.10
## 97     97 irrigado  G14     IV       NA
## 98     98 irrigado  G01      V  6539.86
## 99     99   sequia  G01    III  3203.70
## 100   100 irrigado  G06     IV  7864.08
## 101   101   sequia  G04     IV  2889.83
## 102   102 irrigado  G15      V  6522.46
## 103   103 irrigado  G13    III       NA
## 104   104 irrigado  G02     II  6478.14
## 105   105   sequia  G08     II  2278.60
## 106   106 irrigado  G04    III  8867.03
## 107   107   sequia  G02      V  3063.35
## 108   108   sequia  G06      V  3159.54
## 109   109 irrigado  G15      I  6435.00
## 110   110 irrigado  G13      V  8750.00
## 111   111 irrigado  G05      V  8189.67
## 112   112   sequia  G09    III  2961.78
## 113   113   sequia  G09      V  2781.32
## 114   114   sequia  G10     II  2940.95
## 115   115 irrigado  G07     IV  1989.25
## 116   116 irrigado  G05      I       NA
## 117   117 irrigado  G02      I  4631.00
## 118   118   sequia  G05    III  1967.49
## 119   119 irrigado  G12     II       NA
## 120   120   sequia  G15    III  1601.06
## 121   121 irrigado  G13      I  8256.98
## 122   122   sequia  G14     II  3811.99
## 123   123   sequia  G12     II  2438.98
## 124   124   sequia  G15     II  1560.00
## 125   125 irrigado  G09      V       NA
## 126   126   sequia  G06      I  3381.68
## 127   127   sequia  G09     IV  3150.00
## 128   128   sequia  G15      V  1176.63
## 129   129 irrigado  G14      I       NA
## 130   130   sequia  G06    III  3450.00
## 131   131 irrigado  G01     IV  7750.00
## 132   132 irrigado  G12    III  7164.03
## 133   133   sequia  G12      V  2487.78
## 134   134 irrigado  G12      V  8603.78
## 135   135   sequia  G11      V  2274.26
## 136   136 irrigado  G12     IV  8012.79
## 137   137 irrigado  G09      I 10919.31
## 138   138   sequia  G02    III  2487.28
## 139   139   sequia  G07      I   216.31
## 140   140 irrigado  G08    III  7012.74
## 141   141 irrigado  G06      I  6857.13
## 142   142 irrigado  G10     IV  4743.16
## 143   143 irrigado  G03      V  5369.88
## 144   144   sequia  G07     IV   782.10
## 145   145 irrigado  G05    III  8913.12
## 146   146   sequia  G14      I  3326.93
## 147   147   sequia  G10    III  3096.00
## 148   148 irrigado  G14     II  9221.24
## 149   149 irrigado  G05     II       NA
## 150   150   sequia  G10     IV  2541.12
## 
## 
## $outliers
##     index    riego geno bloque      lfa      resi   res_MAD         rawp.BHStud
## 40     40 irrigado  G09     IV  8533.54 -1821.843 -5.382198 0.00000007358196186
## 41     41 irrigado  G11     II  3966.33 -2921.009 -8.629420 0.00000000000000000
## 44     44 irrigado  G06      V  9040.06  1586.844  4.687948 0.00000275958224139
## 57     57 irrigado  G02     IV  7392.38  1545.147  4.564765 0.00000500053779318
## 58     58 irrigado  G09     II 12296.22  1976.049  5.837760 0.00000000529071831
## 65     65 irrigado  G11    III  8867.09  2014.449  5.951205 0.00000000266175237
## 97     97 irrigado  G14     IV  9776.01  1324.207  3.912051 0.00009151556329234
## 103   103 irrigado  G13    III  7180.79 -1489.351 -4.399930 0.00001082858978219
## 116   116 irrigado  G05      I  7205.94 -1577.072 -4.659080 0.00000317625961999
## 119   119 irrigado  G12     II  6111.43 -1338.287 -3.953649 0.00007696837896431
## 125   125 irrigado  G09      V  8924.78 -1360.784 -4.020111 0.00005817084375703
## 129   129 irrigado  G14      I  6049.52 -2238.868 -6.614197 0.00000000003735745
## 149   149 irrigado  G05     II 10291.06  1379.845  4.076419 0.00004573459036372
##                    adjp            bholm out_flag
## 40  0.00000007358196186 0.00001074296643  OUTLIER
## 41  0.00000000000000000 0.00000000000000  OUTLIER
## 44  0.00000275958224139 0.00040013942500  OUTLIER
## 57  0.00000500053779318 0.00071507690442  OUTLIER
## 58  0.00000000529071831 0.00000077773559  OUTLIER
## 65  0.00000000266175237 0.00000039393935  OUTLIER
## 97  0.00009151556329234 0.01262914773434  OUTLIER
## 103 0.00001082858978219 0.00153765974907  OUTLIER
## 116 0.00000317625961999 0.00045738138528  OUTLIER
## 119 0.00007696837896431 0.01069860467604  OUTLIER
## 125 0.00005817084375703 0.00814391812598  OUTLIER
## 129 0.00000000003735745 0.00000000556626  OUTLIER
## 149 0.00004573459036372 0.00644857724128  OUTLIER
## 
## $diagplot

## 
## $model
## $model$raw
## Linear mixed model fit by REML ['lmerMod']
## Formula: lfa ~ riego * geno + (1 | bloque)
##    Data: rawdt
## REML criterion at convergence: 1976.727
## Random effects:
##  Groups   Name        Std.Dev.
##  bloque   (Intercept) 101.5   
##  Residual             741.6   
## Number of obs: 150, groups:  bloque, 5
## Fixed Effects:
##         (Intercept)          riegosequia              genoG02  
##             7377.89             -4338.30             -1598.33  
##             genoG03              genoG04              genoG05  
##            -1961.12              2291.04              1500.86  
##             genoG06              genoG07              genoG08  
##               77.47             -6003.74               -91.07  
##             genoG09              genoG10              genoG11  
##             2909.82             -2106.55              -523.01  
##             genoG12              genoG13              genoG14  
##               39.37              1294.49              1006.24  
##             genoG15  riegosequia:genoG02  riegosequia:genoG03  
##            -1010.87              1275.79               980.59  
## riegosequia:genoG04  riegosequia:genoG05  riegosequia:genoG06  
##            -2351.92             -2756.77               231.01  
## riegosequia:genoG07  riegosequia:genoG08  riegosequia:genoG09  
##             3644.88              -574.90             -2876.09  
## riegosequia:genoG10  riegosequia:genoG11  riegosequia:genoG12  
##             1991.61              -454.16              -632.55  
## riegosequia:genoG13  riegosequia:genoG14  riegosequia:genoG15  
##            -1207.98              -531.49              -448.22  
## 
## $model$clean
## Linear mixed model fit by REML ['lmerMod']
## Formula: lfa ~ riego * geno + (1 | bloque)
##    Data: cleandt
## REML criterion at convergence: 1651.184
## Random effects:
##  Groups   Name        Std.Dev.
##  bloque   (Intercept) 106.6   
##  Residual             432.2   
## Number of obs: 137, groups:  bloque, 5
## Fixed Effects:
##         (Intercept)          riegosequia              genoG02  
##             7377.89             -4338.30             -1980.26  
##             genoG03              genoG04              genoG05  
##            -1961.12              2291.04              1579.63  
##             genoG06              genoG07              genoG08  
##             -326.74             -6003.74               -91.07  
##             genoG09              genoG10              genoG11  
##             3532.95             -2106.55              -212.24  
##             genoG12              genoG13              genoG14  
##              387.00              1660.20              1312.54  
##             genoG15  riegosequia:genoG02  riegosequia:genoG03  
##            -1010.87              1657.73               980.59  
## riegosequia:genoG04  riegosequia:genoG05  riegosequia:genoG06  
##            -2351.92             -2835.54               635.22  
## riegosequia:genoG07  riegosequia:genoG08  riegosequia:genoG09  
##             3644.88              -574.90             -3499.22  
## riegosequia:genoG10  riegosequia:genoG11  riegosequia:genoG12  
##             1991.61              -764.94              -980.19  
## riegosequia:genoG13  riegosequia:genoG14  riegosequia:genoG15  
##            -1573.69              -837.79              -448.22

3 comparacion de medias

modelo <- aov(formula = lfa ~  bloque + riego + geno + riego*geno
          , data = fb)

anova(modelo)
## Analysis of Variance Table
## 
## Response: lfa
##             Df    Sum Sq   Mean Sq   F value              Pr(>F)    
## bloque       4   3435339    858835    1.5616              0.1892    
## riego        1 788556926 788556926 1433.7957 <0.0000000000000002 ***
## geno        14 261729564  18694969   33.9922 <0.0000000000000002 ***
## riego:geno  14 108147972   7724855   14.0457 <0.0000000000000002 ***
## Residuals  116  63797516    549979                                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

plot(modelo)

3.1 Comparacion de medias con Tukey con chat GPT

3.1.1 Comparacion de medias de tukey (riego )

library(agricolae)
tukey_riego <- HSD.test(modelo, "riego", group = TRUE)
print(tukey_riego)
## $statistics
##    MSerror  Df     Mean       CV      MSD
##   549978.6 116 4806.708 15.42855 239.8611
## 
## $parameters
##    test name.t ntr StudentizedRange alpha
##   Tukey  riego   2         2.801028  0.05
## 
## $means
##               lfa       std  r       se     Min      Max      Q25     Q50
## irrigado 7099.533 2303.6007 75 85.63322 1065.26 12296.22 6080.475 7194.26
## sequia   2513.883  774.8039 75 85.63322  216.31  3811.99 1994.430 2550.51
##               Q75
## irrigado 8676.890
## sequia   3128.035
## 
## $comparison
## NULL
## 
## $groups
##               lfa groups
## irrigado 7099.533      a
## sequia   2513.883      b
## 
## attr(,"class")
## [1] "group"
plot(tukey_riego)

3.1.2 Comparacion de medias de tukey (geno )

tukey_geno <- HSD.test(modelo, "geno", group = TRUE)
print(tukey_geno)
## $statistics
##    MSerror  Df     Mean       CV      MSD
##   549978.6 116 4806.708 15.42855 1149.464
## 
## $parameters
##    test name.t ntr StudentizedRange alpha
##   Tukey   geno  15         4.901424  0.05
## 
## $means
##          lfa       std  r       se     Min      Max       Q25      Q50
## G01 5208.740 2320.6396 10 234.5162 2900.00  7982.73 3024.7450 4871.780
## G02 4248.306 1790.4189 10 234.5162 2449.59  7392.38 2705.6825 3847.175
## G03 3737.911 1774.7220 10 234.5162 1811.97  5545.69 2117.7075 3790.125
## G04 6323.822 3587.6820 10 234.5162 2511.13 10811.84 3062.3600 5916.390
## G05 5331.217 3829.9284 10 234.5162 1657.64 10291.06 1784.2150 4586.715
## G06 5401.719 2269.6009 10 234.5162 3159.54  9040.06 3398.7600 5063.420
## G07 1027.445  508.7517 10 234.5162  216.31  1989.25  789.4375 1067.115
## G08 4830.225 2602.1631 10 234.5162 2021.37  7643.80 2377.4100 4847.965
## G09 6680.517 3942.2332 10 234.5162 2781.32 12296.22 3171.2750 5885.975
## G10 4097.996 1361.9488 10 234.5162 2541.12  6164.24 2979.7125 3692.625
## G11 4458.646 2830.2282 10 234.5162 1556.38  8867.09 2246.9750 3133.820
## G12 4931.831 2694.8614 10 234.5162 2400.00  8603.78 2449.2350 4299.605
## G13 5899.240 3000.7027 10 234.5162 3062.34  9743.70 3126.5475 5186.380
## G14 5949.235 2751.9205 10 234.5162 3318.36  9776.01 3503.4825 4930.755
## G15 3973.766 2529.1790 10 234.5162 1176.63  6522.46 1638.2950 4042.420
##           Q75
## G01  7443.612
## G02  5215.847
## G03  5401.852
## G04  9560.083
## G05  8732.257
## G06  6918.457
## G07  1129.532
## G08  7235.692
## G09 10304.727
## G10  5064.198
## G11  6971.368
## G12  7186.702
## G13  8626.745
## G14  8707.917
## G15  6304.358
## 
## $comparison
## NULL
## 
## $groups
##          lfa groups
## G09 6680.517      a
## G04 6323.822     ab
## G14 5949.235    abc
## G13 5899.240    abc
## G06 5401.719    bcd
## G05 5331.217   bcde
## G01 5208.740  bcdef
## G12 4931.831  cdefg
## G08 4830.225 cdefgh
## G11 4458.646  defgh
## G02 4248.306   efgh
## G10 4097.996    fgh
## G15 3973.766     gh
## G03 3737.911      h
## G07 1027.445      i
## 
## attr(,"class")
## [1] "group"
plot(tukey_geno)

3.1.3 Comparacion de medias de tukey (Interraccion riego y geno)

tukey_interaccion <- HSD.test(modelo, c("riego","geno"), group = TRUE)
print(tukey_interaccion)
## $statistics
##    MSerror  Df     Mean       CV      MSD
##   549978.6 116 4806.708 15.42855 1803.603
## 
## $parameters
##    test     name.t ntr StudentizedRange alpha
##   Tukey riego:geno  30         5.438172  0.05
## 
## $means
##                    lfa        std r      se     Min      Max     Q25      Q50
## irrigado:G01  7377.892  583.61443 5 331.656 6539.86  7982.73 7038.08  7578.79
## irrigado:G02  5779.562 1127.71742 5 331.656 4631.00  7392.38 5162.74  5233.55
## irrigado:G03  5416.770   89.80871 5 331.656 5305.77  5545.69 5369.88  5412.51
## irrigado:G04  9668.932  945.94448 5 331.656 8569.08 10811.84 8867.03  9791.10
## irrigado:G05  8878.756 1235.57574 5 331.656 7205.94 10291.06 8189.67  8913.12
## irrigado:G06  7455.364 1009.33982 5 331.656 6576.65  9040.06 6857.13  6938.90
## irrigado:G07  1374.156  411.10652 5 331.656 1065.26  1989.25 1068.97  1140.05
## irrigado:G08  7286.826  282.80318 5 331.656 6998.00  7643.80 7012.74  7310.01
## irrigado:G09 10287.712 1548.81007 5 331.656 8533.54 12296.22 8924.78 10764.71
## irrigado:G10  5271.344  822.34789 5 331.656 4249.18  6164.24 4743.16  5171.21
## irrigado:G11  6854.880 1888.72290 5 331.656 3966.33  8867.09 6210.41  7225.02
## irrigado:G12  7417.258  946.24681 5 331.656 6111.43  8603.78 7164.03  7194.26
## irrigado:G13  8672.380 1015.60193 5 331.656 7180.79  9743.70 8256.98  8750.00
## irrigado:G14  8384.132 1473.21710 5 331.656 6049.52  9776.01 7895.00  8978.89
## irrigado:G15  6367.026  107.45072 5 331.656 6270.00  6522.46 6302.79  6304.88
## sequia:G01    3039.588  115.85242 5 331.656 2900.00  3203.70 2994.58  2999.66
## sequia:G02    2717.050  281.05239 5 331.656 2449.59  3063.35 2487.28  2618.85
## sequia:G03    2059.052  179.44660 5 331.656 1811.97  2274.48 1953.50  2107.76
## sequia:G04    2978.712  302.61678 5 331.656 2511.13  3263.70 2889.83  3010.27
## sequia:G05    1783.678  120.66794 5 331.656 1657.64  1967.49 1700.00  1771.80
## sequia:G06    3348.074  165.94367 5 331.656 3159.54  3550.19 3198.96  3381.68
## sequia:G07     680.734  335.90739 5 331.656  216.31  1097.98  495.83   782.10
## sequia:G08    2373.624  260.99914 5 331.656 2021.37  2697.93 2278.60  2319.71
## sequia:G09    3073.322  198.12400 5 331.656 2781.32  3238.41 2961.78  3150.00
## sequia:G10    2924.648  235.40497 5 331.656 2541.12  3136.07 2909.10  2940.95
## sequia:G11    2062.412  317.51100 5 331.656 1556.38  2301.31 1942.23  2237.88
## sequia:G12    2446.404   37.06811 5 331.656 2400.00  2487.78 2425.26  2438.98
## sequia:G13    3126.100   47.70803 5 331.656 3062.34  3191.97 3110.00  3120.00
## sequia:G14    3514.338  217.30731 5 331.656 3318.36  3811.99 3326.93  3449.76
## sequia:G15    1580.506  248.79682 5 331.656 1176.63  1814.84 1560.00  1601.06
##                   Q75
## irrigado:G01  7750.00
## irrigado:G02  6478.14
## irrigado:G03  5450.00
## irrigado:G04 10305.61
## irrigado:G05  9793.99
## irrigado:G06  7864.08
## irrigado:G07  1607.25
## irrigado:G08  7469.58
## irrigado:G09 10919.31
## irrigado:G10  6028.93
## irrigado:G11  8005.55
## irrigado:G12  8012.79
## irrigado:G13  9430.43
## irrigado:G14  9221.24
## irrigado:G15  6435.00
## sequia:G01    3100.00
## sequia:G02    2966.18
## sequia:G03    2147.55
## sequia:G04    3218.63
## sequia:G05    1821.46
## sequia:G06    3450.00
## sequia:G07     811.45
## sequia:G08    2550.51
## sequia:G09    3235.10
## sequia:G10    3096.00
## sequia:G11    2274.26
## sequia:G12    2480.00
## sequia:G13    3146.19
## sequia:G14    3664.65
## sequia:G15    1750.00
## 
## $comparison
## NULL
## 
## $groups
##                    lfa groups
## irrigado:G09 10287.712      a
## irrigado:G04  9668.932     ab
## irrigado:G05  8878.756    abc
## irrigado:G13  8672.380    abc
## irrigado:G14  8384.132    bcd
## irrigado:G06  7455.364    cde
## irrigado:G12  7417.258    cde
## irrigado:G01  7377.892    cde
## irrigado:G08  7286.826    cde
## irrigado:G11  6854.880    def
## irrigado:G15  6367.026     ef
## irrigado:G02  5779.562     ef
## irrigado:G03  5416.770      f
## irrigado:G10  5271.344     fg
## sequia:G14    3514.338     gh
## sequia:G06    3348.074     hi
## sequia:G13    3126.100    hij
## sequia:G09    3073.322    hij
## sequia:G01    3039.588    hij
## sequia:G04    2978.712    hij
## sequia:G10    2924.648    hij
## sequia:G02    2717.050    hij
## sequia:G12    2446.404   hijk
## sequia:G08    2373.624   hijk
## sequia:G11    2062.412   hijk
## sequia:G03    2059.052   hijk
## sequia:G05    1783.678   hijk
## sequia:G15    1580.506    ijk
## irrigado:G07  1374.156     jk
## sequia:G07     680.734      k
## 
## attr(,"class")
## [1] "group"
plot(tukey_interaccion)


str(tukey_interaccion)
## List of 5
##  $ statistics:'data.frame':  1 obs. of  5 variables:
##   ..$ MSerror: num 549979
##   ..$ Df     : int 116
##   ..$ Mean   : num 4807
##   ..$ CV     : num 15.4
##   ..$ MSD    : num 1804
##  $ parameters:'data.frame':  1 obs. of  5 variables:
##   ..$ test            : chr "Tukey"
##   ..$ name.t          : chr "riego:geno"
##   ..$ ntr             : int 30
##   ..$ StudentizedRange: num 5.44
##   ..$ alpha           : num 0.05
##  $ means     :'data.frame':  30 obs. of  9 variables:
##   ..$ lfa: num [1:30] 7378 5780 5417 9669 8879 ...
##   ..$ std: num [1:30] 583.6 1127.7 89.8 945.9 1235.6 ...
##   ..$ r  : int [1:30] 5 5 5 5 5 5 5 5 5 5 ...
##   ..$ se : num [1:30] 332 332 332 332 332 ...
##   ..$ Min: num [1:30] 6540 4631 5306 8569 7206 ...
##   ..$ Max: num [1:30] 7983 7392 5546 10812 10291 ...
##   ..$ Q25: num [1:30] 7038 5163 5370 8867 8190 ...
##   ..$ Q50: num [1:30] 7579 5234 5413 9791 8913 ...
##   ..$ Q75: num [1:30] 7750 6478 5450 10306 9794 ...
##  $ comparison: NULL
##  $ groups    :'data.frame':  30 obs. of  2 variables:
##   ..$ lfa   : num [1:30] 10288 9669 8879 8672 8384 ...
##   ..$ groups: chr [1:30] "a" "ab" "abc" "abc" ...
##  - attr(*, "class")= chr "group"

grupos <- tukey_interaccion$groups %>% 
  rownames_to_column("Tratamientos") %>% 
  separate("Tratamientos", into = c("riego","geno"))

str(grupos)
## 'data.frame':    30 obs. of  4 variables:
##  $ riego : chr  "irrigado" "irrigado" "irrigado" "irrigado" ...
##  $ geno  : chr  "G09" "G04" "G05" "G13" ...
##  $ lfa   : num  10288 9669 8879 8672 8384 ...
##  $ groups: chr  "a" "ab" "abc" "abc" ...
ggplot(grupos, aes(x = geno, y = lfa, fill = riego)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  labs(title = "Efecto de Geno y Riego en LFA",
       x = "Genotipo",
       y = "LFA") +
  theme_minimal() +
  scale_fill_discrete(name = "Riego") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

3.1.4 Letras en graficos

ggplot(grupos, aes(x = geno, y = lfa, fill = riego)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_text(aes(label = groups), 
            position = position_dodge(width = 0.9), 
            vjust = -0.3, 
            size = 3) +  
  labs(title = "Efecto de Geno y Riego en LFA",
       x = "Genotipo",
       y = "LFA") +
  theme_minimal() +
  scale_fill_discrete(name = "Riego") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

4 emmeans: comparacion de medias

source('https://inkaverse.com/setup.r')
library(emmeans)
library(multcomp)
library(multcompView)

modelo <- lme4::lmer(lfa ~ riego * geno + (1 | bloque), data = fb)

anova(modelo)
## Analysis of Variance Table
##            npar    Sum Sq   Mean Sq  F value
## riego         1 788556926 788556926 1433.796
## geno         14 261729564  18694969   33.992
## riego:geno   14 108147972   7724855   14.046

cm1 <- emmeans(modelo , ~  geno | riego) %>% 
  cld(Letters = letters, reversed = T )
cm1
## riego = irrigado:
##  geno emmean  SE  df lower.CL upper.CL .group   
##  G09   10288 335 119   9624.9    10951  a       
##  G04    9669 335 119   9006.1    10332  ab      
##  G05    8879 335 119   8215.9     9542  abc     
##  G13    8672 335 119   8009.5     9335  abc     
##  G14    8384 335 119   7721.3     9047   bcd    
##  G06    7455 335 119   6792.5     8118    cde   
##  G12    7417 335 119   6754.4     8080    cde   
##  G01    7378 335 119   6715.1     8041    cdef  
##  G08    7287 335 119   6624.0     7950    cdef  
##  G11    6855 335 119   6192.0     7518     defg 
##  G15    6367 335 119   5704.2     7030      efg 
##  G02    5780 335 119   5116.7     6442       fg 
##  G03    5417 335 119   4753.9     6080        g 
##  G10    5271 335 119   4608.5     5934        g 
##  G07    1374 335 119    711.3     2037         h
## 
## riego = sequia:
##  geno emmean  SE  df lower.CL upper.CL .group   
##  G14    3514 335 119   2851.5     4177  a       
##  G06    3348 335 119   2685.2     4011  ab      
##  G13    3126 335 119   2463.3     3789  abc     
##  G09    3073 335 119   2410.5     3736  abc     
##  G01    3040 335 119   2376.7     3702  abc     
##  G04    2979 335 119   2315.9     3642  abc     
##  G10    2925 335 119   2261.8     3587  abc     
##  G02    2717 335 119   2054.2     3380  abc     
##  G12    2446 335 119   1783.6     3109  abc     
##  G08    2374 335 119   1710.8     3036  abc     
##  G11    2062 335 119   1399.6     2725  abcd    
##  G03    2059 335 119   1396.2     2722  abcd    
##  G05    1784 335 119   1120.8     2447   bcd    
##  G15    1581 335 119    917.7     2243    cd    
##  G07     681 335 119     17.9     1344     d    
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 15 estimates 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping symbol,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.

cm2 <- emmeans(modelo , ~  riego | geno) %>% 
  cld(Letters = letters, reversed = T )
cm2
## geno = G01:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   7378 335 119   6715.1     8041  a    
##  sequia     3040 335 119   2376.7     3702   b   
## 
## geno = G02:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   5780 335 119   5116.7     6442  a    
##  sequia     2717 335 119   2054.2     3380   b   
## 
## geno = G03:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   5417 335 119   4753.9     6080  a    
##  sequia     2059 335 119   1396.2     2722   b   
## 
## geno = G04:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   9669 335 119   9006.1    10332  a    
##  sequia     2979 335 119   2315.9     3642   b   
## 
## geno = G05:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   8879 335 119   8215.9     9542  a    
##  sequia     1784 335 119   1120.8     2447   b   
## 
## geno = G06:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   7455 335 119   6792.5     8118  a    
##  sequia     3348 335 119   2685.2     4011   b   
## 
## geno = G07:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   1374 335 119    711.3     2037  a    
##  sequia      681 335 119     17.9     1344  a    
## 
## geno = G08:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   7287 335 119   6624.0     7950  a    
##  sequia     2374 335 119   1710.8     3036   b   
## 
## geno = G09:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado  10288 335 119   9624.9    10951  a    
##  sequia     3073 335 119   2410.5     3736   b   
## 
## geno = G10:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   5271 335 119   4608.5     5934  a    
##  sequia     2925 335 119   2261.8     3587   b   
## 
## geno = G11:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   6855 335 119   6192.0     7518  a    
##  sequia     2062 335 119   1399.6     2725   b   
## 
## geno = G12:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   7417 335 119   6754.4     8080  a    
##  sequia     2446 335 119   1783.6     3109   b   
## 
## geno = G13:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   8672 335 119   8009.5     9335  a    
##  sequia     3126 335 119   2463.3     3789   b   
## 
## geno = G14:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   8384 335 119   7721.3     9047  a    
##  sequia     3514 335 119   2851.5     4177   b   
## 
## geno = G15:
##  riego    emmean  SE  df lower.CL upper.CL .group
##  irrigado   6367 335 119   5704.2     7030  a    
##  sequia     1581 335 119    917.7     2243   b   
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping symbol,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.

cm3 <- emmeans(modelo , ~  riego * geno)%>% 
  cld(Letters = letters, reversed = T )
cm3
##  riego    geno emmean  SE  df lower.CL upper.CL .group      
##  irrigado G09   10288 335 119   9624.9    10951  a          
##  irrigado G04    9669 335 119   9006.1    10332  ab         
##  irrigado G05    8879 335 119   8215.9     9542  abc        
##  irrigado G13    8672 335 119   8009.5     9335  abc        
##  irrigado G14    8384 335 119   7721.3     9047   bcd       
##  irrigado G06    7455 335 119   6792.5     8118    cde      
##  irrigado G12    7417 335 119   6754.4     8080    cde      
##  irrigado G01    7378 335 119   6715.1     8041    cde      
##  irrigado G08    7287 335 119   6624.0     7950    cde      
##  irrigado G11    6855 335 119   6192.0     7518     def     
##  irrigado G15    6367 335 119   5704.2     7030      ef     
##  irrigado G02    5780 335 119   5116.7     6442      ef     
##  irrigado G03    5417 335 119   4753.9     6080       f     
##  irrigado G10    5271 335 119   4608.5     5934       fg    
##  sequia   G14    3514 335 119   2851.5     4177        gh   
##  sequia   G06    3348 335 119   2685.2     4011         hi  
##  sequia   G13    3126 335 119   2463.3     3789         hij 
##  sequia   G09    3073 335 119   2410.5     3736         hij 
##  sequia   G01    3040 335 119   2376.7     3702         hij 
##  sequia   G04    2979 335 119   2315.9     3642         hij 
##  sequia   G10    2925 335 119   2261.8     3587         hij 
##  sequia   G02    2717 335 119   2054.2     3380         hij 
##  sequia   G12    2446 335 119   1783.6     3109         hijk
##  sequia   G08    2374 335 119   1710.8     3036         hijk
##  sequia   G11    2062 335 119   1399.6     2725         hijk
##  sequia   G03    2059 335 119   1396.2     2722         hijk
##  sequia   G05    1784 335 119   1120.8     2447         hijk
##  sequia   G15    1581 335 119    917.7     2243          ijk
##  irrigado G07    1374 335 119    711.3     2037           jk
##  sequia   G07     681 335 119     17.9     1344            k
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 30 estimates 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping symbol,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.

#grafica

library(ggplot2)
dtcm <- as.data.frame(cm1) %>% 
  rename(sig = ".group")

ggplot(dtcm, aes(x = geno, y = emmean, fill = riego)) +
  geom_bar(stat = "identity", position = "dodge", color =
             "black") +
  geom_text(aes(label = sig, y = emmean),
            position = position_dodge(width = 0.9),
            vjust = 0) +
  labs(x = "Genotipo", y = "HI", fill = "Riego") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ggtitle("Gráfico de barras: LFA por genotipo y riego")

5 Analisis multivariado

5.1 Corelacion

variables_cuantitativas <- fb[, c("lfa", "hi", "leafdw", "wue")]

matriz_correlacion <- cor(variables_cuantitativas, method = "pearson")

print(matriz_correlacion)
##                lfa          hi     leafdw         wue
## lfa     1.00000000 -0.04955964  0.7859616 -0.36555108
## hi     -0.04955964  1.00000000 -0.3419763  0.08840298
## leafdw  0.78596157 -0.34197634  1.0000000 -0.17692519
## wue    -0.36555108  0.08840298 -0.1769252  1.00000000

library(corrplot)
corrplot(matriz_correlacion, method = "circle", type = "upper", 
         tl.col = "black", tl.srt = 45, 
         title = "Matriz de Correlación", mar = c(0, 0, 1, 0))

library(PerformanceAnalytics)
my_data <- fb[, c("lfa", "hi", "leafdw", "wue", "op_84")]
chart.Correlation(my_data, histogram=TRUE, pch=19)

library(tidyverse)
library(psych)
fb %>% 
  select_if(is.numeric) %>% 
 dplyr::select(!c("block")) %>% 
pairs.panels(x = .
      , hist.col="blue"
      , pch = 21
      , stars = TRUE 
      , scale = FALSE 
      , lm= TRUE
      )

5.2 PCA: Análisis de componentes principales

library(FactoMineR)

mv <- fb %>% 
  group_by(riego, geno) %>% 
  summarise(across(where(is.numeric), ~ mean(., na.rm = TRUE))) %>% 
  PCA(scale.unit = T, quali.sup = c(1:4), graph = F)


p1 <- plot(mv
     , choix="ind"
     , habillage=1
     , label = "ind"
     )


p2 <- plot(mv
     , choix="var")

list(p1, p2) %>% 
  plot_grid(plotlist = ., nrow = 1)

6 Grafica en ggplot2

6.1 Graficos en data cruda

6.1.1 Box plot

p1 <- fb %>% 
    ggplot(data = ., aes(x = geno, y = hi, fill = riego)) + geom_boxplot() +
  labs(x= "Genotipos"
       , y = "Indice de cosecha"
       , fill= "Tratamiento"
       , title ="Eficiencia de uso de agua en papa"
       , subtitle = "Indice de cosecha"
       , caption = "n= 150") +
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5))

p1

6.2 Scater plot

library(ggplot2)
library(dplyr)

p2 <- fb %>%
  ggplot(data = ., aes(x = twue, y = hi, fill = riego)) +
  geom_point()+
  geom_smooth(method = lm) + 
  labs(title = "Eficiencia de uso de agua en papa",
       subtitle = "Índice de cosecha vs eficiencia de uso de agua en papa",
       x = "Eficiencia de uso de agua en papa",
       y = "Índice de cosecha", 
       color = "Riego",
       caption = "n = 150") +
  theme_bw()+ 
  theme(plot.title = element_text(hjust = 0.5))

p2

6.2.1 Resumir datos

modelo <- lm(lfa ~ bloque + riego*geno 
             , data = fb)

anova (modelo)
## Analysis of Variance Table
## 
## Response: lfa
##             Df    Sum Sq   Mean Sq   F value              Pr(>F)    
## bloque       4   3435339    858835    1.5616              0.1892    
## riego        1 788556926 788556926 1433.7957 <0.0000000000000002 ***
## geno        14 261729564  18694969   33.9922 <0.0000000000000002 ***
## riego:geno  14 108147972   7724855   14.0457 <0.0000000000000002 ***
## Residuals  116  63797516    549979                                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(agricolae)
 tukey <- HSD.test(modelo 
                   , c("geno", "riego")
                   , group = TRUE)

grupos <- tukey_interaccion$groups %>% 
  rownames_to_column("Tratamientos") %>% 
  separate("Tratamientos", into = c("riego","geno"), sep = ":")
p3 <- grupos %>% 
  ggplot(data = . 
         , aes(x = geno, y = lfa, fill = riego)) + 
  geom_col(position = position_dodge2(preserve = "single"))

p3

library(psych)

p4 <- function() {
  
    fb %>% 
  select_if(is.numeric) %>% 
  dplyr::select(!c("block")) %>% 
  pairs.panels(x = .
               , hist.col="red"
               , pch = 21
               , stars = TRUE
               , scale = FALSE
               , lm = TRUE
               ) 
}
  
p4
## function() {
##   
##     fb %>% 
##   select_if(is.numeric) %>% 
##   dplyr::select(!c("block")) %>% 
##   pairs.panels(x = .
##                , hist.col="red"
##                , pch = 21
##                , stars = TRUE
##                , scale = FALSE
##                , lm = TRUE
##                ) 
## }

7 imagenes in grids

library(cowplot)

plot <- list(p1, p2, p3, p4) %>% 
  plot_grid(plotlist = .
            , ncol = 2
            , labels = "auto"
            )

ggsave2(filename = "plot-01.jpg", units = "cm"
        , width = 30*2, height = 15*2.5)

include_graphics("plot-01.jpg")